package edu.pku.sei.transformation.editor.model;

import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.xml.XMLUtility;

public abstract class Relationship extends MetaModelElement {
	protected MetaModelElement sourceElement;
	protected MetaModelElement targetElement;

	@Override
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeNodeNotContain(root,
				ModelPackage.RELATIONSHIP_SOURCE, sourceElement);
		XMLUtility.xmlInstance.serializeNodeNotContain(root,
				ModelPackage.RELATIONSHIP_TARGET, targetElement);
	}

	@Override
	public void deSerialize(Element root) {
		super.deSerialize(root);
		this.sourceElement = (MetaModelElement) XMLUtility.xmlInstance
				.deSerializeNodeNotContain(root,
						ModelPackage.RELATIONSHIP_SOURCE, this);
		this.targetElement = (MetaModelElement) XMLUtility.xmlInstance
				.deSerializeNodeNotContain(root,
						ModelPackage.RELATIONSHIP_TARGET, this);
	}

	@Override
	public void dynamicSet(String featureID, Object value) {
		if (ModelPackage.RELATIONSHIP_SOURCE.equals(featureID)) {
			this.sourceElement = (MetaModelElement) value;
		} else if (ModelPackage.RELATIONSHIP_TARGET.equals(featureID)) {
			this.targetElement = (MetaModelElement) value;
		} else {
			super.dynamicSet(featureID, value);
		}
	}
}
